#ifdef __cplusplus
extern "C" {
#endif


#include "WorkBench.h"
#include "MenuService.h"
#include "Command.h"
#include "MainMenu.h"

__bsingleton(WorkBench)

LRESULT __procedure(WorkBench, procedure)
	HWND _tHandle, UINT _tMessage, WPARAM _twParam, LPARAM _tlParam
__begbody
	switch (_tMessage)
	{
	    case WM_COMMAND:
			{
				UINT id = LOWORD(_twParam);
				MenuService * menuService = __instance(MenuService)
				__foreach(&(menuService->mCommands), VectorCommand, &id, Commandrun)
			}
			break;
		case WM_DESTROY:
			PostQuitMessage (0);
			break;
		default:
			return DefWindowProc (_tHandle, _tMessage, _twParam, _tlParam);
	}
	return 0;

__endbody

void __begvoid(WorkBench, showGraceful)
__begbody

	__begfun(&(__this(WorkBench)->mForm), Form, showGraceful)
	    SW_SHOWNORMAL
	__endfun

__endbody


void __begvoid(WorkBench, initialize)
__begbody
	FormDescriptor formDescriptor;
	formDescriptor.mCaption = L"www.kugong.com";
	formDescriptor.mClassName = L"WorkBench";
	formDescriptor.mMenuName = NULL;
	formDescriptor.mWndProc = __name(WorkBench, procedure);
	__begfun(&(__this(WorkBench)->mForm), Form, initialize)
		&formDescriptor
	__endfun

	MenuService * menuService = __instance(MenuService);
	__voidfun(menuService, MenuService, initialize)

	Menu * menu = __instance(Menu);
	__voidfun(menu, Menu, initialize)

	__name(MainMenu, initialize)();

	__begfun(&(__this(WorkBench)->mForm), Form, addMenu)
	    menu
	__endfun

__endbody


#ifdef __cplusplus
}
#endif



